package com.translation.utils;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class Mail {
	private static final String HOST_KEY = "mail.stmp.host";
	private static final String AUTH_KEY = "mail.smtp.auth";
	private String host;
	private String from;
	private String to;
	private String user;
	private String password;
	private String subject;
	private String content;
	public String getHost() {
		return host;
	}
	public void setHost(String host) {
		this.host = host;
	}
	public String getFrom() {
		return from;
	}
	public void setFrom(String from) {
		this.from = from;
	}
	public String getTo() {
		return to;
	}
	public void setTo(String to) {
		this.to = to;
	}
	public String getUser() {
		return user;
	}
	public void setUser(String user) {
		this.user = user;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	
	public void send() throws AddressException, MessagingException{
		Properties props = new Properties();
		props.put(HOST_KEY, host);
		props.put(AUTH_KEY, true);
		
		Session mailSession = Session.getDefaultInstance(props);
		Message message = new MimeMessage(mailSession);
		message.setFrom(new InternetAddress(from));
		message.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
		message.setSubject(subject);
		message.setText(content);
		message.saveChanges();
		
		Transport transport = mailSession.getTransport("smtp");
		transport.connect(host, user, password);
		transport.sendMessage(message,message.getAllRecipients());
		
		transport.close();
		
	}
}
